package com.cleaner.base.utils

import android.app.Application
import android.os.Bundle
import com.yandex.metrica.YandexMetrica
import com.yandex.metrica.YandexMetricaConfig


object Events {

    internal fun initialize(application: Application) {
        val config = YandexMetricaConfig.newConfigBuilder("62082231-fcc3-4a23-8222-e676ffefa860")
            .build()
        YandexMetrica.activate(application, config)
        YandexMetrica.enableActivityAutoTracking(application)
    }

    @JvmStatic
    fun sendEvent(name: String) {
        YandexMetrica.reportEvent(name)
    }

    @JvmStatic
    fun sendEvent(name: String, params: Map<String, Any?>) {
        YandexMetrica.reportEvent(name, params)
    }

    @JvmStatic
    fun sendEvent(name: String, bundle: Bundle) {
        val params = bundle.keySet().map {
            Pair(it, bundle.get(it))
        }.toMap()
        sendEvent(name, params)
    }

    @JvmStatic
    fun sendEvent(name: String, eventObject: EventObject) {
        YandexMetrica.reportEvent(name, mapOf(eventObject.key to eventObject.params))
    }
}

data class EventObject(val key: String, val params: Any?)